package BiShi.huyu;


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main2{
        static int cnt = 0;
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            while(sc.hasNext()){
                int n = sc.nextInt();
                if(n==0){
                    System.out.println(0);
                }
                else{
                    int[] W = new int[n];
                    int[] T = new int[n];
                    for(int i = 0; i < n; i++){
                        W[i] = sc.nextInt();
                    }
                    for(int i = 0; i < n; i++){
                        T[i] = sc.nextInt();
                    }
                    int mod = sc.nextInt();
                    helper(W, T, new boolean[n], new ArrayList<Integer>());
                    System.out.println(cnt % mod);
                    cnt = 0;
                }
            }
        }

    public static void helper(int[] W, int[] T, boolean[] visited, ArrayList<Integer> arr){
        if(arr.size()>0 && W[arr.size()-1]  < arr.get(arr.size()-1)){
            return;
        }
        if(W.length == arr.size()){
            cnt++;
            return;
        }

        for(int i = 0; i < W.length; i++){
            if(visited[i] == false){
                visited[i] = true;
                arr.add(T[i]);
                helper(W, T , visited, arr);
                visited[i] = false;
                arr.remove(arr.size()-1);
            }
        }
    }

}
